Attempts to remove an item from the
BlockingCollection<(Of <(T>)>).
A
OperationCanceledException is thrown if the
CancellationToken is
canceled.
Namespace:
System.Collections.Concurrent
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Function TryTake ( _
<OutAttribute> ByRef item As T, _
millisecondsTimeout As Integer, _
cancellationToken As CancellationToken _
) As Boolean |
C# |
---|
public bool TryTake(
out T item,
int millisecondsTimeout,
CancellationToken cancellationToken
) |
Parameters
- item
- Type:
T
%
The item removed from the collection.
- millisecondsTimeout
- Type: System..::.Int32
The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.
- cancellationToken
- Type: System.Threading..::.CancellationToken
A cancellation token to observe.
Return Value
true if an item could be removed from the collection within
the alloted time; otherwise, false.
Exceptions
Exception | Condition |
---|
System..::.OperationCanceledException | If the CancellationToken is canceled. |
System..::.ObjectDisposedException | The BlockingCollection<(Of <(T>)>) has been disposed. |
System..::.ArgumentOutOfRangeException | millisecondsTimeout is a
negative number other than -1, which represents an infinite time-out. |
System..::.InvalidOperationException | The underlying collection was modified
outside of this BlockingCollection<(Of <(T>)>) instance. |
See Also